package com.bs.demo.vo;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bs.demo.mapper.CasesMapper;
import com.bs.demo.po.Cases;
import lombok.Data;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * @author bingshao
 * @date 2022/9/23
 **/
@Data
public class CallDemoVo implements Callable<List<Cases>>, Serializable {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private Integer startIndex;

    private Integer Length;

    private CasesMapper casesMapper;

    private static final long serialVersionUID = -2878616667383949362L;

    @Override
    public List<Cases> call() throws Exception {
        List<Cases> casesList = casesMapper.selectList(new LambdaQueryWrapper<Cases>().last("limit " + startIndex + "," + Length));
        casesList.forEach(cases -> {
            try {
                FileWriter fw = new FileWriter(new File("C:\\Users\\admin\\Desktop\\test.txt"), true);
                PrintWriter pw = new PrintWriter(fw);
                pw.println(JSON.toJSONString(cases));
                pw.flush();
                fw.flush();
                pw.close();
                fw.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
//            System.out.println(sdf.format(new Date()) + cases);
        });
        return casesList;
    }
}
